package com.mall.admin.controller;

import com.mall.admin.service.SmsFlashPromotionProductRelationService;
import com.mall.commons.utils.PageResult;
import com.mall.commons.utils.R;
import com.mall.domain.SmsFlashPromotionProductRelation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController {

    @Autowired
    private SmsFlashPromotionProductRelationService smsFlashPromotionProductRelationService;

    //批量选择商品添加关联
    @PostMapping("/create")
    public R create(@RequestBody List<SmsFlashPromotionProductRelation> relationList){
        smsFlashPromotionProductRelationService.create(relationList);
        return R.success("批量关联",null);
    }

    //删除关联
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        smsFlashPromotionProductRelationService.delete(id);
        return R.success("删除关联",null);
    }

    //分页查询不同场次关联及商品信息
    @GetMapping("/list")
    public R list(Map map, Integer pageNum, Integer pageSize){
        PageResult pageResult = smsFlashPromotionProductRelationService.list(map,pageNum,pageSize);
        return R.success("分页关联",pageResult);
    }

    //修改关联信息
    @PostMapping("/update/{id}")
    public R update(@PathVariable Long id,@RequestBody SmsFlashPromotionProductRelation smsFlashPromotionProductRelation){
        smsFlashPromotionProductRelationService.update(id,smsFlashPromotionProductRelation);
        return R.success("修改关联信息",null);
    }

    //获取管理商品促销信息
    @GetMapping("/{id}")
    public R find(@PathVariable Long id){
        SmsFlashPromotionProductRelation smsFlashPromotionProductRelation = smsFlashPromotionProductRelationService.find(id);
        return R.success("获取管理商品促销信息",smsFlashPromotionProductRelation);
    }

}
